home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 2
/
Gold Medal Software Volume 2 (Gold Medal) (1994).iso
/
utils
/
fgscroll.arj
/
SCROLL.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-13
|
9KB
|
383 lines
// (c) 1993 John M. Warren
// 10/01/1993
// This code is for educational purposes only.
// This is my first C program. I just skipped HELLO WORLD
// and went for the guts and glory of C++ <g>
//
// you must run Fastgraph Lite 3.03 graphics engine before
// running this program.
// written with Turbo C++ 3.0
//
// Some fine games coming to you soon!!
// Code 3 The Programmers Connection 904-535-1705 14.4k
// (programming, game programming code!!)
// --------------------------------------------------------------
#include <string.h>
#include "boolean.h"
enum DIRECTION{north=0,south=1,west=2,east=3}; // north up
DIRECTION HerosDirection=north; // facing up
Boolean GODMODEACTIVE = true;
Boolean DEAD = false;
unsigned char WORKPAGE= 1;
unsigned char DISPLAYPAGE= 0;
unsigned char SCRAPPAGE = 2;
unsigned char TILEPAGE= 3;
const MAPSIZEX = 64;
const MAPSIZEY = 64;
const DRAWINGWIDTH = 13 * 16; // width of drawing area for tiles
const DRAWINGHEIGTH = 11 * 16; // heigth of drawing area for tiles
// the three cordinate sytstems
// mapptrx,mapptry current x,y postion in pixels of the entire game mape
// blockptrx,blockptry current x,y position in 16 pixel blocks of the entire game mape
// HERO_X,HERO_Y x,y offset of the hero within the drawing area
const blockptrmaxx = MAPSIZEX - 13;
const blockptrmaxy = MAPSIZEY - 12;
short int MapPositionX,MapPositionY; // current x,y position in pixels
// relative to the game map
char blockptrx=0,blockptry=0; // current x,y position in 16 pixel blocks
// i.e. postionX / 16 postionY /16
// current block number
unsigned char HERO_X, HERO_Y;
unsigned char map[MAPSIZEY][MAPSIZEX]; // holds background tile data
unsigned char spritemap[DRAWINGHEIGTH][DRAWINGWIDTH]; // holds sprite data use as global collision table
// 11*16 13*16
struct tilestruct{
int x,y;
int spritewidth,spriteheigth;
};
tilestruct TILES[256];
#include <stdlib.h>
#include <dos.h>
#include <fastgraf.h> // fastgraph library
#include <alloc.h>
#include "keyint.h"
#include "scancode.h"
#include "fileio.c"
#include "sprites.h"
//----------------------- keyboard stuff
struct keyboard {
unsigned shiftRight : 1;
unsigned shiftLeft : 1;
unsigned ctrl : 1;
unsigned alt : 1;
unsigned scrollLock : 1;
unsigned numLock : 1;
unsigned capsLock : 1;
unsigned insert : 1;
unsigned : 8;
};
keyboard far *keys = (keyboard far *) MK_FP(0x0040, 0x0017);
void playdemo();
void flippage();
void rebuildbackground();
main(){
randomize();
fg_setmode(20);
fg_tcmask(1);
keyint(ON);
playdemo();
freelist();
keyint(OFF);
fg_reset();
fg_setmode(3);
return 0;
}
char offsetx=0,offsety=0;
void playdemo(){
MapPositionX = 0; MapPositionY = 0; // fine tune the scroll off by 8 pixels used by drawbackground()
blockptrx = 0; blockptry = 0; // fine tune the scroll off by 8 pixels used by drawbackground()
HERO_X = 40; HERO_Y = 40; // initial position of the hero inside the DRAWING AREA!!
// create the sprite list
alist = (struct atomstruct *) malloc(sizeof(struct atomstruct));
alist->asprite = geticon(HERO_X,HERO_Y,AHERO);
alist->avalue = 0;
alist->next = NULL;
alist->prev = NULL;
ptrlast = alist;
int x,y;
for(x=0;x<MAPSIZEX;x++){
for(y=0;y<MAPSIZEY;y++){
map[y][x] = 0;
}}
//for(x=20;x<60;x++){ y = 1+random(50); map[y][x] = 3;}
TILES[AHERO+north].x =0;
TILES[AHERO+north].y =16;
TILES[AHERO+north].spritewidth = 15;
TILES[AHERO+north].spriteheigth = 15;
TILES[AHERO+south].x =16;
TILES[AHERO+south].y =16;
TILES[AHERO+south].spritewidth = 15;
TILES[AHERO+south].spriteheigth = 15;
TILES[AHERO+west].x =32;
TILES[AHERO+west].y =16;
TILES[AHERO+west].spritewidth = 15;
TILES[AHERO+west].spriteheigth = 15;
TILES[AHERO+east].x =48;
TILES[AHERO+east].y =16;
TILES[AHERO+east].spritewidth = 15;
TILES[AHERO+east].spriteheigth = 15;
TILES[0].x = 156;
TILES[0].y = 87;
TILES[3].x = 0;
TILES[3].y = 0;
TILES[1].x = 32;
TILES[1].y = 0;
TILES[2].x = 16;
TILES[2].y = 0;
TILES[5].x = 48;
TILES[5].y = 0;
TILES[4].x = 64;
TILES[4].y = 0;
/*
for(x=0;x<MAPSIZEX;x++) {
map[1][x] = 2; // top
map[2][x] = 2;
map[62][x] = 2; // bottom
map[63][x] = 2;
map[x][0] = 2; // left
map[x][1] = 2;
map[x][62] = 2; // right
map[x][63] = 2;
}
TILES[0].x = 0;
TILES[0].y = 40;
*/
// map[1][MAPSIZEX] = 1;
// map[63][0] = 2;
// map[63][63] = 1;
LoadFile("1.map", map[0], MAPSIZEX * MAPSIZEY); // load map
fg_setpage(SCRAPPAGE);
fg_showpcx("DROP.PCX\0",0);
fg_setpage(TILEPAGE);
fg_setvpage(DISPLAYPAGE);
fg_showpcx("TILE.PCX\0",0);
//unsigned char manptrx=7,manptry=9;
//rebuildbackground();
//flippage();
char string[25];
Boolean STOPPED = false;
while(!STOPPED){
rebuildbackground();
fg_setcolor(4);
fg_setpage(DISPLAYPAGE);
/*
fg_locate(0,0);
fg_text("MapPositionX",12);
itoa(MapPositionX, string, 10);
fg_text(string,strlen(string));
fg_locate(10,0);
fg_text("MapPositionY",12);
itoa(MapPositionY, string, 10);
fg_text(string,strlen(string));
fg_locate(20,0);
fg_text("HERO_X",6);
itoa(HERO_X, string, 10);
fg_text(string,strlen(string));
fg_locate(30,0);
fg_text("HERO_Y",6);
itoa(HERO_Y, string, 10);
fg_text(string,strlen(string));
*/
alist->asprite->MoveTo(HERO_X,HERO_Y);
alist->asprite->Move();
alist->asprite->Draw();
flippage();
// fg_copypage(DISPLAYPAGE,WORKPAGE); // make backup copy
switch(KEYPRESSED){
case ESC :
STOPPED = true;
break;
case LEFT:
HerosDirection = west;
HERO_X=HERO_X-8;
if(HERO_X < 24){
HERO_X = 24;
offsetx = !offsetx;
if(!offsetx){
MapPositionX = MapPositionX - 8;
if(MapPositionX < 0) {
MapPositionX = 0; // 16 * 64 - 16 * 13
offsetx = !offsetx;
}
}
}
break;
case RIGHT:
HerosDirection = east;
HERO_X=HERO_X+8;
if(HERO_X > 184){
HERO_X = 184;
offsetx = !offsetx;
if(offsetx){
MapPositionX = MapPositionX + 8;
if(MapPositionX > 408) {
MapPositionX = 408; // 16 * 64 - 16 * 13
offsetx = !offsetx;
}
}
}
break;
case UP:
HerosDirection = north;
HERO_Y=HERO_Y-8;
if(HERO_Y < 24){
HERO_Y = 24;
offsety = !offsety;
if(!offsety){
MapPositionY = MapPositionY - 8;
if(MapPositionY < 0) {
MapPositionY = 0;
offsety = !offsety;
}
}
}
break;
case DOWN:
HerosDirection = south;
HERO_Y=HERO_Y+8;
if(HERO_Y > 152){
HERO_Y = 152;
offsety = !offsety;
if(offsety){
MapPositionY = MapPositionY + 8;
if(MapPositionY > 424) {
MapPositionY = 424; // 16 * 64 - 16 * 13
offsety = !offsety;
}
}
}
break;
}// end case
}// end while
} // end playdemo()
void rebuildbackground(){
unsigned char shifty=0,shiftx=0;
unsigned char tempx,tempy,MAPVALUE;
unsigned char tx,ty;
// fg_transfer(17,208,22,181,17,181,SCRAPPAGE,WORKPAGE); // copy background mask
char tempoffsetx = offsetx << 3; // same as multiplying by 8 but faster
char tempoffsety = offsety << 3;
blockptrx = MapPositionX / 8;
blockptry = MapPositionY / 8;
for(unsigned char x=0;x<208;x=x+16){ // 10 16 pixel tiles
for(unsigned char y=0;y<176;y=y+16){
MAPVALUE = map[blockptry+shifty][blockptrx+shiftx];
tempx = TILES[MAPVALUE].x;
tempy = TILES[MAPVALUE].y;
// if(MAPVALUE != 0) // don't copy 0 value tiles, let the background mask bleed through .. quicker
fg_transfer(tempx,tempx+15,tempy,tempy+15,1+x+tempoffsetx,21+y+tempoffsety,TILEPAGE,WORKPAGE);
shifty++;
}
shifty=0;
shiftx++;
}
// clip a copy of the static background around the working page
// building the scoreboard frame
fg_transfer(17,209,0,21,17,21,SCRAPPAGE,WORKPAGE); // top
fg_transfer(0,16,0,199,0,199,SCRAPPAGE,WORKPAGE); // left
fg_transfer(17,209,182,199,17,199,SCRAPPAGE,WORKPAGE); // bottom
fg_transfer(208,319,0,199,208,199,SCRAPPAGE,WORKPAGE); // right
}
// simulate page flipping by modifying the vga page register
// ultra fast page flipping
void flippage(){
if(WORKPAGE)
{
fg_pan(0,200);
WORKPAGE = 0;
} else
{
fg_pan(0,0);
WORKPAGE=1;
}
}